<template>
    <div id="seachDialog">
      <a-modal
        title="选择负责人"
        v-model="createdData.show"
        width="520px"
        style="overflow:hidden"
        @cancel="handleClose">
        <el-row style="padding:20px 30px">
            <el-form ref="Form" size="small" :model="parames" label-width="80px">
                <el-form-item label="负责人" prop="person">
                    <userTree v-model="parames.person" :currentValue="parames.person"></userTree>
                </el-form-item>
            </el-form>
        </el-row>
        <span slot="footer" class="dialog-footer">
            <el-button size="small" @click="handleClose">取消</el-button>
            <el-button size="small" type="primary" @click="handleSave">保存</el-button>
        </span>
      </a-modal>
    </div>
</template>

<script>
export default {
    props: ['createdData'],
    data() {
        return {
          parames: {
              person: '',
          },
          rules: {
            person: [{ required: true, message: '必填', trigger: ['change','blur' ]}],
          }
        };
    },
    methods: {
        handleClose () {
            this.createdData.show = false
        },
        checkValue (value) { //来源获取信息
            this.parames.sourceTypeEnum = value
        },
        handleSave () {
            this.$refs['Form'].validate((valid) => {
                if (valid) {
                    if (this.createdData.type=='shangji') {
                        this.$post(this.$api.postOpportunityTransfer,{
                            opportunityId: this.createdData.id,
                            person: this.parames.person,
                        }).then(response => {
                            if (response.data.succeed) {
                                this.$emit('checkRender')
                                this.$message({
                                    message: '修改成功',
                                    type: 'success'
                                });
                                this.handleClose()
                            }
                        })
                    } else if (this.createdData.type == 'kehu') {
                        this.$post(this.$api.postCustomerCoreTransfer,{
                            customerId: this.createdData.id,
                            person: this.parames.person,
                        }).then(response => {
                            if (response.data.succeed) {
                                this.$emit('checkRender')
                                this.$message({
                                    message: '修改成功',
                                    type: 'success'
                                });
                                this.handleClose()
                            }
                        })
                    } else if (this.createdData.type == 'Allshangji') {
                        this.$post(this.$api.postOpportunityBatchTransfer,{
                            opportunityIds: this.createdData.ids,
                            person: this.parames.person,
                        }).then(response => {
                            if (response.data.succeed) {
                                this.$emit('checkRender')
                                this.$message({
                                    message: '操作成功',
                                    type: 'success'
                                });
                                this.handleClose()
                            }
                        })
                    } else if (this.createdData.type == 'AllEc') {
                        this.$post(this.$api.postEcBatchTransfer,{
                            robotIds: this.createdData.ids,
                            person: this.parames.person,
                        }).then(response => {
                            if (response.data.succeed) {
                                this.$emit('checkRender')
                                this.$message({
                                    message: '操作成功',
                                    type: 'success'
                                });
                                this.handleClose()
                            }
                        })
                    } else if (this.createdData.type == 'Allkehu') {
                        this.$post(this.$api.postCustomerCoreBatchTransfer,{
                            customerIds: this.createdData.ids,
                            person: this.parames.person,
                        }).then(response => {
                            if (response.data.succeed) {
                                this.$emit('checkRender')
                                this.$message({
                                    message: '操作成功',
                                    type: 'success'
                                });
                                this.handleClose()
                            }
                        })
                    } else if (this.createdData.type == 'oneList') {
                        this.$post(this.$api.posTaskDisposableDistribute,{
                            contractProductIds: this.createdData.ids,
                            distributedUserId: this.parames.person,
                        }).then(response => {
                            if (response.data.succeed) {
                                this.$emit('checkRender')
                                this.$message({
                                    message: '操作成功',
                                    type: 'success'
                                });
                                this.handleClose()
                            }
                        })
                    }
                }       
            })
        },
        resetData () {
            this.parames.person = ''
        }
    },
    computed: {
      changeDialog () {
        return this.createdData.show
      }
    }, 
    watch: {
      changeDialog: {
        handler (curVal, oldVal) {
          if (curVal) {
            this.parames.person = this.createdData.directorId
          } else {
            this.resetData()
          }
        }
      }
    }
};
</script>

<style>
#seachDialog .el-dialog{
    padding-bottom: 0; 
    overflow-x: hidden;
}
#seachDialog .el-dialog__footer{
    border-top: #f4f4f4 solid 1px;
}
</style>
